package com.fenghao.subject.common.enums;

import lombok.Getter;

/**
 * 题目类型的枚举
 */
@Getter
public enum SubjectInfoTypeEnum {

    RADIO(1, "单选题"),
    MULTIPLE(2, "多选题"),
    JUDGE(3, "判断题"),
    BRIEF(4, "简答题");

    private final int code;
    private final String desc;

    SubjectInfoTypeEnum(int code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    // 通过 code 获取枚举
    public static SubjectInfoTypeEnum getEnumByCode(int codeVal) {
        SubjectInfoTypeEnum[] subjectInfoTypeEnums = SubjectInfoTypeEnum.values();
        for (SubjectInfoTypeEnum subjectInfoTypeEnum : subjectInfoTypeEnums) {
            if (subjectInfoTypeEnum.code == codeVal) {
                return subjectInfoTypeEnum;
            }
        }
        return null;
    }

    // 通过 desc 获取枚举
    public static SubjectInfoTypeEnum getEnumByDesc(String descVal) {
        SubjectInfoTypeEnum[] subjectInfoTypeEnums = SubjectInfoTypeEnum.values();
        for (SubjectInfoTypeEnum subjectInfoTypeEnum : subjectInfoTypeEnums) {
            if (subjectInfoTypeEnum.desc.equals(descVal)) {
                return subjectInfoTypeEnum;
            }
        }
        return null;
    }
}
